{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "\n",
    "# 视频文件路径\n",
    "video_path = './02_Video/00_Scenery.mp4'\n",
    "\n",
    "# 创建视频捕获对象\n",
    "cap = cv2.VideoCapture(video_path)\n",
    "\n",
    "# 检查视频是否打开成功\n",
    "if not cap.isOpened():\n",
    "    print(\"Error: Could not open video.\")\n",
    "    exit()\n",
    "\n",
    "# 读取视频帧的宽度和高度\n",
    "frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))\n",
    "frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))\n",
    "\n",
    "# 循环直到视频结束\n",
    "while True:\n",
    "    # 读取视频的下一帧\n",
    "    ret, frame = cap.read()\n",
    "\n",
    "    # 如果正确读取帧，ret为True\n",
    "    if not ret:\n",
    "        print(\"Can't receive frame (stream end?). Exiting ...\")\n",
    "        break\n",
    "\n",
    "    # 画一条红色的线\n",
    "    # 参数分别是：图像，起点坐标，终点坐标，颜色(B,G,R)，线条宽度\n",
    "    cv2.line(frame, (0, frame_height // 2), (frame_width, frame_height // 2), (0, 0, 255), 3)\n",
    "\n",
    "    # 显示处理后的帧\n",
    "    cv2.imshow('Video with Red Line', frame)\n",
    "\n",
    "    # 按 'q' 键退出循环\n",
    "    if cv2.waitKey(25) & 0xFF == ord('q'):\n",
    "        break\n",
    "\n",
    "# 释放视频捕获对象\n",
    "cap.release()\n",
    "# 关闭所有窗口\n",
    "cv2.destroyAllWindows()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
